//
//  XYJXCResultFrameModel.m
//  徙游记-01
//
//  Created by hcios on 2017/7/12.
//  Copyright © 2017年 鹿林. All rights reserved.
//

#import "XYJXCResultFrameModel.h"

#define TitleFont [UIFont systemFontOfSize:15]
#define ContextFont [UIFont systemFontOfSize:13]

@implementation XYJXCResultFrameModel

-(void)setModel:(XYJXCResultModel *)model{
    _model = model;
    CGFloat padding = 10;
    
    //标题
//    if (model.xc_plan_days_entry_name == nil) {
    if([model.xc_plan_days_entry_name isEqualToString:@""]){
        CGSize titleSize = [self sizeWithText:@"今日备忘" font:[UIFont fontWithName:FONT_NAME_LTH size:15] maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
        CGFloat titleW = titleSize.width;
        CGFloat titleH = titleSize.height;
        self.titleFrame = RECT_MAKE(padding, padding, titleW, titleH);
    }else{
        CGSize titleSize = [self sizeWithText:model.xc_plan_days_entry_name font:[UIFont fontWithName:FONT_NAME_LTH size:15] maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
        CGFloat titleW = titleSize.width;
        CGFloat titleH = titleSize.height;
        self.titleFrame = RECT_MAKE(padding, padding, titleW, titleH);
    }
    
    
    
    //文字
    if ([model.xc_plan_days_memo isEqualToString:@""]) {
        self.topLabFrame = RECT_MAKE(padding, CGRectGetMaxY(self.titleFrame) + padding, 0, 0);
    }else{
        CGSize topLabSize = [self sizeWithText:model.xc_plan_days_memo font:ContextFont maxSize:CGSizeMake(SCREEN_WIDTH - padding * 2, MAXFLOAT)];
        self.topLabFrame = RECT_MAKE(padding, CGRectGetMaxY(self.titleFrame) + 5, topLabSize.width, topLabSize.height);
    }
    
    
    
    //图像
//    if (model.xc_plan_days_image_url == nil) {
    if([model.xc_plan_days_image_url isEqualToString:@""]){
        self.imageViewFrame = RECT_MAKE(padding, CGRectGetMaxY(self.topLabFrame) + 5, 0, 0);
    }else{
        self.imageViewFrame = RECT_MAKE(padding, CGRectGetMaxY(self.topLabFrame) + 5, SCREEN_WIDTH - (2 * padding), 170);
    }
    
    
    //文字
    if ([model.xc_plan_days_tips isEqualToString:@""]) {
        self.contextFrame = RECT_MAKE(padding, CGRectGetMaxY(self.imageViewFrame) + 5, 0, 0);
    }else{
        CGSize textSize = [self sizeWithText:model.xc_plan_days_tips font:ContextFont maxSize:CGSizeMake(SCREEN_WIDTH - padding * 2, MAXFLOAT)];
        self.contextFrame = CGRectMake(padding, CGRectGetMaxY(self.imageViewFrame) + 5, textSize.width, textSize.height);
    }
    _cellHeight = CGRectGetMaxY(self.contextFrame) + padding * 2;
}


-(CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize{
    NSDictionary *dict = @{NSFontAttributeName:font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
}

@end
